package com.ruoyi.web.controller.organization;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.organization.domain.BizGrid;
import com.ruoyi.organization.service.IBizGridService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 网格Controller
 * 
 * @author ruoyi
 * @date 2024-05-07
 */
@RestController
@RequestMapping("/organization/grid")
public class BizGridController extends BaseController
{
    @Autowired
    private IBizGridService bizGridService;

    /**
     * 查询网格列表
     */
    @PreAuthorize("@ss.hasPermi('organization:grid:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizGrid bizGrid)
    {
        startPage();
        List<BizGrid> list = bizGridService.selectBizGridList(bizGrid);
        return getDataTable(list);
    }

    /**
     * 导出网格列表
     */
    @PreAuthorize("@ss.hasPermi('organization:grid:export')")
    @Log(title = "网格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizGrid bizGrid)
    {
        List<BizGrid> list = bizGridService.selectBizGridList(bizGrid);
        ExcelUtil<BizGrid> util = new ExcelUtil<BizGrid>(BizGrid.class);
        util.exportExcel(response, list, "网格数据");
    }

    /**
     * 获取网格详细信息
     */
    @PreAuthorize("@ss.hasPermi('organization:grid:query')")
    @GetMapping(value = "/{gridId}")
    public AjaxResult getInfo(@PathVariable("gridId") Long gridId)
    {
        return success(bizGridService.selectBizGridByGridId(gridId));
    }
    /**
     * 获取网格详细信息
     */
    @PreAuthorize("@ss.hasPermi('organization:grid:query')")
    @GetMapping(value = "/getGridListBy/{communityId}")
    public AjaxResult getGridList(@PathVariable("communityId") Long communityId)
    {
        return success(bizGridService.getGridListBy(communityId));
    }

    /**
     * 新增网格
     */
    @PreAuthorize("@ss.hasPermi('organization:grid:add')")
    @Log(title = "网格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizGrid bizGrid)
    {
        bizGrid.setCreateBy(getUsername());
        return toAjax(bizGridService.insertBizGrid(bizGrid));
    }

    /**
     * 修改网格
     */
    @PreAuthorize("@ss.hasPermi('organization:grid:edit')")
    @Log(title = "网格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizGrid bizGrid)
    {
        bizGrid.setUpdateBy(getUsername());
        return toAjax(bizGridService.updateBizGrid(bizGrid));
    }

    /**
     * 删除网格
     */
    @PreAuthorize("@ss.hasPermi('organization:grid:remove')")
    @Log(title = "网格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gridIds}")
    public AjaxResult remove(@PathVariable Long[] gridIds)
    {
        return toAjax(bizGridService.deleteBizGridByGridIds(gridIds));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('organization:grid:edit')")
    @Log(title = "状态修改", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody BizGrid grid)
    {
        grid.setUpdateBy(getUsername());
        return toAjax(bizGridService.updateBizGrid(grid));
    }
}
